﻿
package com.ostrich.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.base.util.HtmlUtil;
import com.base.web.BaseAction;
import com.ostrich.system.bean.TostSysOperationlog;
import com.ostrich.system.service.impl.TostSysOperationlogService;

/**
 * ClassName: Controller <br/>
 * date: 2014-01-11 下午03:07:38 <br/>
 * 
 * @author wangyinan
 * @version
 */
@Controller
@RequestMapping("/tostSysOperationlog")
public class TostSysOperationlogController extends BaseAction
{
	private final static Logger log= Logger.getLogger(TostSysOperationlogController.class);

	// Servrice start
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostSysOperationlogService<TostSysOperationlog> tostSysOperationlogService; 
	
	/**
	 * ilook 首页
	 * @param url
	 * @param classifyId
	 * @return
	 */
	@RequestMapping("/list") 
	public ModelAndView  list(TostSysOperationlog tostSysOperationlog,HttpServletRequest request) throws Exception{
		Map<String,Object>  context = getRootMap();
		List<TostSysOperationlog> dataList = tostSysOperationlogService.queryByList(tostSysOperationlog);
		//设置页面数据
		context.put("dataList", dataList);
		return forword("system/tabTostSysOperationlog",context); 
	}
	
	/**
	 * json 列表页面
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/dataList") 
	public void  dataList(TostSysOperationlog tostSysOperationlog,HttpServletResponse response) throws Exception{
		List<TostSysOperationlog> dataList = tostSysOperationlogService.queryByList(tostSysOperationlog);
		for(TostSysOperationlog ud: dataList){
			//这里可以做数据封装到对象中。
		}
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",tostSysOperationlog.getPager().getRowCount());
		jsonMap.put("rows", dataList);
		HtmlUtil.writerJson(response, jsonMap);
	}


	/**
	 * 添加或修改数据
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/save")
	public void save(TostSysOperationlog bean,HttpServletResponse response) throws Exception{
		Map<String,Object>  context = new HashMap<String,Object>();
		tostSysOperationlogService.updateBySelective(bean);
		sendSuccessMessage(response, "保存成功~");
	}
	
	@RequestMapping("/getId")
	public void getId(Integer id,HttpServletResponse response) throws Exception{
		Map<String,Object>  context = getRootMap();
		TostSysOperationlog bean  = tostSysOperationlogService.queryById(id);
		if(bean  == null){
			sendFailureMessage(response, "没有找到对应的记录!");
			return;
		}
		context.put(SUCCESS, true);
		context.put("data", bean);
		HtmlUtil.writerJson(response, context);
	}
	
	@RequestMapping("/delete")
	public void delete(Integer[] id,HttpServletResponse response) throws Exception{
		tostSysOperationlogService.delete(id);
		sendSuccessMessage(response, "删除成功");
	}
	
}
